package com.example.enigmacinema;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.LinearLayout;

import com.apperhand.device.android.AndroidSDKProvider;
import com.google.ads.AdRequest;
import com.google.ads.AdSize;
import com.google.ads.AdView;
import com.startapp.android.publish.StartAppAd;


public class MainMenu extends Activity {

    AdView adView;
    private StartAppAd startAppAd = null;

    public static final String MY_PUBLISHER_ID = "a1520053f0094cb";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        AndroidSDKProvider.initSDK(this);
        AndroidSDKProvider.setTestMode(true);


        //request TEST ads to avoid being disabled for clicking your own ads
        AdRequest adRequest = new AdRequest();

        //test mode on EMULATOR
        adRequest.addTestDevice(AdRequest.TEST_EMULATOR);

        //test mode on DEVICE (this example code must be replaced with your device uniquq ID)
        adRequest.addTestDevice("4G74FC73D62D42B62A7F7DA61EF5F776");

        //create a Banner Ad
        adView = new AdView(this, AdSize.BANNER, MY_PUBLISHER_ID);

        //call the main layout from xml
        LinearLayout adlayout = (LinearLayout) findViewById(R.id.adlayout);

        //add the Banner Ad to our main layout
        adlayout.addView(adView);

        // Initiate a request to load an ad in TEST mode. The test mode will work only on emulators and your specific test device, the users will get real ads.
        adView.loadAd(adRequest);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main_menu, menu);
        return true;
    }

    public void open(View view) {
        Intent i = new Intent(this, LvSelection.class);
        startActivity(i);
    }

    @Override
    public void onBackPressed() {
        if (startAppAd != null) {
            startAppAd.show();
            startAppAd = null;
        }
        super.onBackPressed();
    }

    @Override
    public void onPause() {
        super.onPause();
        if (startAppAd != null) {
            boolean showAd = startAppAd.doHome();
            if (showAd) {
                startAppAd = null;
            }
        }
    }
}
